package leetcode;

public class Q2470 {
    static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public int subarrayLCM(int[] nums, int k) {
        int res = 0;
        for (int i = 0; i < nums.length; ++i) {
            int t = nums[i];
            for (int j = i; j < nums.length; ++j) {
                t = (t * nums[j]) / gcd(t, nums[j]);
                if (t == k) {
                    ++res;
                } else if (t > k) break;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Q2470 sl = new Q2470();
        int[] nums = {3, 6, 2, 7, 1};
        System.out.println(sl.subarrayLCM(nums, 6));
    }
}


